package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcRegistrationEntity;
import com.dhcc.cdc.busi.service.ICdcRegistrationService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 挂号
 * 
 * @ClassName: CdcRegistrationController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:07
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcregistration")
public class CdcRegistrationController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcregistration/";

	@Autowired
	private ICdcRegistrationService cdcRegistrationService;
	

    /**
     * 跳转到挂号列表首页
     */
    @RequestMapping("")
    @Permission("cdcregistration:list")
    public String index() {
        return PREFIX + "cdcregistration.html";
    }
	
    /**
     * 跳转到新增挂号
     */
    @RequestMapping("/to_add")
    @Permission("cdcregistration:add")
    public String toAdd() {
        return PREFIX + "cdcregistration_add.html";
    }
	
	/**
     * 跳转到修改挂号
     */
    @RequestMapping("/to_update/{cdcRegistrationId}")
    @Permission("cdcregistration:update")
    public String toUpdate(@PathVariable Long cdcRegistrationId, Model model) {
        CdcRegistrationEntity cdcRegistration = this.cdcRegistrationService.selectById(cdcRegistrationId);
        model.addAttribute("cdcRegistration",cdcRegistration);
        return PREFIX + "cdcregistration_edit.html";
    }

    /**
     * 获取挂号列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcregistration:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcRegistrationEntity> page = new PageFactory<CdcRegistrationEntity>().defaultPage();
        List<CdcRegistrationEntity> result = this.cdcRegistrationService.page(page,params);
        page.setRecords((List<CdcRegistrationEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增挂号
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcregistration:add")
    @BussinessLog(value = "新增挂号")
    public Object add(CdcRegistrationEntity cdcRegistration) {
        if (CommonUtil.isOneEmpty(cdcRegistration)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcRegistration.insert();
        return R.ok();
    }

    /**
     * 删除挂号
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcregistration:delete")
    @BussinessLog(value = "删除挂号")
    public Object delete(@RequestParam Long cdcRegistrationId) {
	
        this.cdcRegistrationService.deleteById(cdcRegistrationId);

        return R.ok();
    }

    /**
     * 修改挂号
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcregistration:update")
    @BussinessLog(value = "修改挂号")
    public Object update(CdcRegistrationEntity cdcRegistration) {
        if (CommonUtil.isOneEmpty(cdcRegistration)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcRegistrationEntity old = this.cdcRegistrationService.selectById(cdcRegistration.getId());

        old.setEpisodeId(cdcRegistration.getEpisodeId());
        old.setRegLocId(cdcRegistration.getRegLocId());
        old.setBusRegCateId(cdcRegistration.getBusRegCateId());
        old.setBusRegTypeId(cdcRegistration.getBusRegTypeId());
        old.setBusRegRouteId(cdcRegistration.getBusRegRouteId());
        old.setRegUserId(cdcRegistration.getRegUserId());
        old.setRegDate(cdcRegistration.getRegDate());
        old.setDataId(cdcRegistration.getDataId());
        old.setIsActive(cdcRegistration.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
